#include <stdio.h>
#include <stdlib.h>
#include <math.h>

void work(float* b, int n, int m)
{
    int i;
#pragma omp simd safelen(16)
    for (i = m; i < n; i++) {
        b[i] = b[i - m] - 1.0f;
    }
}

void test_case(const char* name, int n, int m, float* input, float* expected)
{
    printf("\nTest case [%s]:\n", name);

    float* b = malloc(n * sizeof(float));
    if (n > 0) {
        for (int i = 0; i < n; i++) b[i] = input[i];
    }

    work(b, n, m);

    int passed = 1;
    for (int i = 0; i < n; i++) {
        if (fabs(expected[i] - b[i]) > 1e-6) {
            printf("Error at [%d]: got %.2f, expected %.2f\n", i, b[i], expected[i]);
            passed = 0;
        }
    }

    printf("Result: %s\n", passed ? "Passed" : "Failed");
    free(b);
}

int main()
{
    // Normal case
    {
        float input[] = { 0,1,2,3,4,5,6,7 };
        float expected[] = { 0,1,-1,0,-2,-1,-3,-2 };
        test_case("Normal case n=8 m=2", 8, 2, input, expected);
    }

    // m=1 test
    {
        float input[] = { 1,2,3,4,5 };
        float expected[] = { 1,0,-1,-2,-3 };
        test_case("m=1 test", 5, 1, input, expected);
    }

    // Boundary case
    {
        float input[] = { 10 };
        float expected[] = { 10 };
        test_case("Boundary case n=1", 1, 1, input, expected);
    }

    // Empty array test
    test_case("Empty array test", 0, 0, NULL, NULL);

    return 0;
}